<!DOCTYPE html>
<html>
<head>
    <title>计算时间差</title>
    <style>
        body {
            background-color: #f5f5f5;
            font-family: Arial, sans-serif;
            text-align: center;
        }

        h1 {
            color: #333;
        }

        label {
            display: block;
            margin-top: 20px;
            font-size: 18px;
            font-weight: bold;
            color: #333;
        }

        input[type=datetime-local] {
            margin-top: 10px;
            padding: 5px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 4px;
            outline: none;
        }

        button {
            margin-top: 20px;
            padding: 10px 20px;
            font-size: 16px;
            color: #fff;
            background-color: #007bff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        button:hover {
            background-color: #0056b3;
        }

        #result {
            margin-top: 20px;
            font-size: 20px;
            font-weight: bold;
        }
    </style>
    <script>
        function calculateHours() {
            // 获取起始时间和结束时间的输入值
            var startDateTime = document.getElementById('startDateTime').value;
            var endDateTime = document.getElementById('endDateTime').value;

            // 将输入值转换为日期对象
            var startDate = new Date(startDateTime);
            var endDate = new Date(endDateTime);

            // 计算时间差，单位为毫秒
            var timeDiff = endDate.getTime() - startDate.getTime();

            // 将毫秒转换为小时
            var hours = timeDiff / (1000 * 60 * 60);

            // 显示计算结果
            document.getElementById('result').innerHTML = "时间差为：" + hours + "小时";
        }
    </script>
</head>
<body>
    <h1>计算时间差</h1>
    <label for="startDateTime">起始时间：</label>
    <input type="datetime-local" id="startDateTime">
    <br>
    <label for="endDateTime">结束时间：</label>
    <input type="datetime-local" id="endDateTime">
    <br>
    <button onclick="calculateHours()">计算</button>
    <br>
    <p id="result"></p>
</body>
</html>